#ifndef Filebuf_First
#define Filebuf_First
#ifdef __GNUG__
#pragma interface
#endif

#include "StreamBuf.h"

enum open_mode { input= 0, output= 1, append= 2 };

//---- Filebuf -----------------------------------------------------------------

class Filebuf : public StreamBuf {     // a Stream buffer for files
	int fd;         // file descriptor
	bool opened;    // non-zero if file has been opened

public:
	Filebuf();
	Filebuf(int nfd);
	Filebuf(int nfd, char* p, int l);
	Filebuf(const char *path, open_mode m);

	~Filebuf();

	bool isopen()
		{ return opened; }

	// Open a file. return 0 if failure; return "this" if success
	Filebuf* open(const char *name, open_mode om);

	bool close();
	int Overflow(u_char *bp, int size);
	int Underflow(u_char *p, int l);
	long Seek(long pos, int whence);
};

#endif
